using System;
using System.Collections.Generic;
using System.Text;
using MacomberMap.Common.User_Interfaces.Components;
using System.Drawing;
using System.Xml;
using System.Windows.Forms;
using System.ComponentModel;
using MacomberMap.Common.Database_Interface;

namespace MacomberMap.Common.User_Interfaces.One_Lines.Elements
{
    /// <summary>
    /// This class holds information on a one-line element not linked into CIM
    /// </summary>
    public class MM_OneLine_UnlinkedElement : MM_OneLine_Element
    {
        #region Enumerations
        /// <summary>
        /// The collection of unlinked element types
        /// </summary>
        public enum UnlinkedElementType
        {
            /// <summary>A text box with fixed text</summary>
            TextBox,
            /// <summary>An oval</summary>
            Oval,
            /// <summary>A rectangle</summary>
            Rectangle,
            /// <summary>An arrow</summary>
            Arrow
        }
        #endregion

        #region Variable declarations
        /// <summary>The data-connected element to which we're connected (if any)</summary>
        public MM_OneLine_Element Owner;

        /// <summary>The type of element this unlinked one is</summary>
        public UnlinkedElementType ElemType;

        /// <summary>The thickness of the oval/rectangle/arrow</summary>
        [Category("Display"), Description("The thickness of the oval/rectangle/arrow")]
        public float ShapeWidth
        {
            get { return _ShapeWidth; }
            set { _ShapeWidth = value; }
        }
        private float _ShapeWidth = 1f;



        /// <summary>Whether the shape is filled</summary>
        [Category("Display"), Description("Whether the shape is filled")]
        public bool Filled
        {
            get { return _Filled; }
            set { _Filled = value; }
        }
        private bool _Filled;

        /// <summary>If an arrow, the points associated with it</summary>
        public Point[] ArrowPoints;
        #endregion


        #region Initialization
        /// <summary>
        /// Initialize a new unlinked element
        /// </summary>
        /// <param name="BaseConfiguration">The configuration for the unlinked element</param>
        /// <param name="DisplayParameters">The display parameters for the element</param>
        /// <param name="DbConnection">The database connection</param>
        public MM_OneLine_UnlinkedElement(XmlElement BaseConfiguration, MM_OneLine_Display DisplayParameters, MM_Database DbConnection)
            : base(BaseConfiguration, DisplayParameters, DbConnection)
        {          

        }
        /// <summary>
        /// Initialize a new unlinked element
        /// </summary>
        /// <param name="ElemType">The element type</param>
        /// <param name="DisplayParameters">The display parameters for the element</param>        
        public MM_OneLine_UnlinkedElement(UnlinkedElementType ElemType, MM_OneLine_Display DisplayParameters)
            : base(DisplayParameters)
        { }

        /// <summary>
        /// Initialize a new unlinked element
        /// </summary>
        /// <param name="DisplayParameters">The display parameters for the element</param>        
        public MM_OneLine_UnlinkedElement(MM_OneLine_Display DisplayParameters)
            : base(DisplayParameters)
        { }
        #endregion

        #region Rendering
        /// <summary>
        /// Draw the image for the unlinked element
        /// </summary>
        /// <param name="g"></param>
        public override void DrawImage(Graphics g)
        {
            if (ElemType == UnlinkedElementType.Rectangle && Filled)
                using (SolidBrush sB = new SolidBrush(ForeColor))
                    g.FillRectangle(sB, DisplayRectangle);
            else if (ElemType == UnlinkedElementType.Rectangle)
                using (Pen BoundPen = new Pen(ForeColor, ShapeWidth))
                    g.DrawRectangle(BoundPen, DisplayRectangle);
            else if (ElemType == UnlinkedElementType.Oval && Filled)
                using (SolidBrush sB = new SolidBrush(ForeColor))
                    g.FillEllipse(sB, DisplayRectangle);
            else if (ElemType == UnlinkedElementType.Oval)
                using (Pen BoundPen = new Pen(ForeColor, ShapeWidth))
                    g.DrawEllipse(BoundPen, DisplayRectangle);
            else if (ElemType == UnlinkedElementType.TextBox)
                using (SolidBrush sB = new SolidBrush(ForeColor))
                    g.DrawString(Text, Font, sB, DisplayRectangle);
            else if (ElemType == UnlinkedElementType.Arrow)
                using (Pen BoundPen = new Pen(ForeColor, ShapeWidth))
                {
                    BoundPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                    g.DrawLines(BoundPen, ArrowPoints);
                }

        }
        #endregion
    }
}